Reads the item at the top of target WITHOUT removing it. If target is empty, returns a plain default value instead (see stack_pop's own note on what that is per type) - target is left unchanged either way.
stack_peek(target) -> element| Name | Type |
|---|---|
target | stack |
element
Reads the item at the top of target WITHOUT removing it. target is left unchanged either way.
If target is empty, returns a plain default value instead - the same rule stack_pop uses (0/0.0/false/an empty string/nothing, depending on target's element type). Useful for deciding what to do with the top item before committing to actually removing it.
/// @type {stack<int>}
var history = [1, 2, 3];
var top = stack_peek(history); // 3 - history is still [1, 2, 3]



the GBA module's own vector back() - O(1), guarded by an empty() check first so it is never called on an empty vector (which would be undefined behavior, not just a wrong answer).